package com.uvt.agenda;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

public class EventsListAdapter extends ArrayAdapter {

    public EventsListAdapter(Context context, List objects) {
        super(context, R.layout.view_item_type, objects);
        setDropDownViewResource(R.layout.view_item_type);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(getContext(), R.layout.events_list_adapter_item, null);
            holder = new ViewHolder();
            holder.eventTitle = (TextView) convertView.findViewById(R.id.event_title);
            holder.eventDescription = (TextView) convertView.findViewById(R.id.event_description);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // Bind the data efficiently with the holder.
        Event event = (Event) getItem(position);
        holder.eventTitle.setText(event.getName());
        holder.eventDescription.setText(event.getDescription());

        return convertView;
    }

    /**
     *
     * Inner holder class for a single row view in the ListView
     *
     */
    static class ViewHolder {
        TextView eventTitle;
        TextView eventDescription;
    }

}